//console.log('kreiraj_sadrzaj')
var answers;
var votesectionbottom;
var resultsectionbottom;
function kreiraj_sadrzaj(){    
    var table = jQuery(""+
    "<table width='100%' cellpadding=0 cellspacing=0><tbody><tr><td align='center'>"+
    "<div id='poll'><div class='lss-box'></div></div></td></tr></tbody></table>");   
    var qusetion = jQuery("<div class='lss-question-top'>"+LS_pollquestion+"</div>");
    var pollimage = jQuery("<div><img src='"+sys_url+"assets/upload/fotografije-na-anketi/"+LS_pollimg+"'></div>");
    answers = jQuery("<div class='lss-answer'><div id='lss-answer"+LS_pollid+"'></div></div>"); 
    /*KREIRAJ SADRZAJ ANKETE*/
    jQuery('#lspollholder-'+LS_pollid).append(table);
    if(LS_pollimg!='') jQuery('.lss-box').append(pollimage);
    jQuery('.lss-box').append(qusetion);
    jQuery('.lss-box').append(answers);
    /*KREIRAJ ODGOVORE ANKETE*/    
    var q_id;
    var q_text;
    if(LS_pollrandomize==1) LS_answers.sort( function() {return 0.5 - Math.random()} ) //RANDOMIZE QUESTION ORDER
    jQuery.each(LS_answers, function(index, answer) {
        q_id = LS_answers[index].id;
        q_text = LS_answers[index].text;
        var answergroup;
        if(LS_pollmultipleselection==0){
            answergroup  = jQuery("<div class='lss-answer-group'><div class='lss-answer-input'>"+
            "<input type='radio' name='LSI_answer"+LS_pollid+"' value='"+q_id+"' id='LSI_answer"+q_id+"' class='lss-radiobutton'>"+
            "</div><div class='lss-input-label'><div class='lss-answer-span'>"+q_text+"</div></div>"+
            "<div class='lss-clear'></div></div>");
        }else{
            answergroup  = jQuery("<div class='lss-answer-group'><div class='lss-answer-input'>"+
            "<input type='checkbox' name='LSI_answer"+LS_pollid+"' value='"+q_id+"' id='LSI_answer"+q_id+"' class='lss-radiobutton'>"+
            "</div><div class='lss-input-label' ><div class='lss-answer-span'>"+q_text+"</div></div>"+
            "<div class='lss-clear'></div><br></div>"); 
        }
        jQuery('#lss-answer'+LS_pollid).append(answergroup);
    });
    /*KREIRAJ POLJE ZA SOPSTVENI ODGOVOR ANKETE*/
    if(LS_pollownanswer==1){
        var answergroup;
        if(LS_pollmultipleselection==0){
            answergroup  = jQuery("<div class='lss-answer-group'><div class='lss-answer-input'>"+
            "<input type='radio' name='LSI_answer"+LS_pollid+"' value='0' id='LSI_answer"+q_id+"' class='lss-radiobutton'></div>"+
            "<div class='lss-input-label'><div class='lss-answer-span'>Ostalo</div></div>"+
            "<div class='lss-answer-other'><br><input type='text' name='LSI_OtherText' id='LSI_OtherText' maxlength='80' class='lss-textfield'>"+
            "</div><div class='lss-clear'></div><br></div>");
        }else{
            answergroup  = jQuery("<div class='lss-answer-group'><div class='lss-answer-input'>"+
            "<input type='checkbox' name='LSI_answer"+LS_pollid+"' value='0' id='OtherAnswer' class='lss-radiobutton'>"+
            "</div><div class='lss-input-label'><div class='lss-answer-span'>Ostalo</div></div>"+
            "<div class='lss-answer-other'><br><input type='text' name='LSI_OtherText' id='LSI_OtherText' maxlength='80' class='lss-textfield'>"+
            "</div><div class='lss-clear'></div><br></div>"); 
        }
        jQuery('#lss-answer'+LS_pollid).append(answergroup); 
    }
    votesectionbottom = jQuery("<div class='lss-clear'></div><div class='lss-vote'>"+
    "<a class='lss-vote-button' id='lss-vote-button' href='javascript:void(0);' style='float:left'><span>Glasaj</span></a>"+
    "<a class='lss-vote-button lss-view-results' href='javascript:void(0);' style='float:left'><span>Pogledaj rezultate</span></a>"+
    "<div class='lss-clear'></div></div><div class='lss-clear'></div>");
    resultsectionbottom = jQuery("<div class='lss-clear'></div><div class='lss-vote'>"+
    "<div class='lss-totalvotes-inner'><div style='float:left'>Ukupno glasova:</div><b><div id='t_votes' style='float:left'>"+LS_totalvotes+"</div></b><div class='lss-clear'></div></div>"+
    "<div id='lss-links'><br><a class='lss-view-poll' href='javascript:void(0);' style='padding-left:0;padding-right:0'>"+
    "Povratak na anketu</a><div class='lss-clear'></div></div><div class='lss-clear'></div></div>");
    jQuery('.lss-box').append(votesectionbottom);
}
function kreiraj_rezultate(){
    jQuery.each(votes_num, function(index) { 
        var poll_width = klase_stilovi['pollbox']['width'];
        var totalwidth = poll_width-(12*2);
        var reset = "";
        if(votes_prc[index]==0){
            reset = "padding-left:0px; padding-right:0px; margin-left:0px; margin-right:0px; border:none";
        }  
        var resultgroup = jQuery("<div class='lss-result-group'><div class='lss-result-label lss-answer-span'>"+answer_text[index]+" <b>"+
        votes_prc[index]+ "%</b> - glasova: <b>"+votes_num[index]+"</b></div><div class='lss-result-feedback'>"+
        "<div class='lss-result-feedback-bar' style='width:"+votes_prc[index]+"%;"+reset+"'></div></div></div>");   
        jQuery('#lss-answer'+LS_pollid).append(resultgroup);
    });
    /*UPDATE TOTAL VOTES*/        
    jQuery("#t_votes").text(LS_totalvotes);
}
